package flc.ast.adapter;

import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.PorterDuff;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.constraintlayout.utils.widget.ImageFilterView;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyCameraFilterBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class CameraFilterAdapter extends StkProviderMultiAdapter<MyCameraFilterBean> {

    public CameraFilterAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(76));
        addItemProvider(new CameraFilterProvider());
    }

    private class CameraFilterProvider extends BaseItemProvider<MyCameraFilterBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_filter;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyCameraFilterBean bean) {
            baseViewHolder.setText(R.id.tvFilterItemName, bean.getName());
            ImageFilterView view = baseViewHolder.getView(R.id.ivFilterItemImg);
            if (bean.getColor().equals("#C376F3")) {
                // 创建一个ColorMatrix，将其设置为黑白滤镜
                ColorMatrix colorMatrix = new ColorMatrix();
                colorMatrix.setSaturation(0);  // 将饱和度设为0，即黑白效果
                // 使用ColorMatrixColorFilter来应用这个ColorMatrix
                ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
                view.setColorFilter(colorFilter);
            } else {
                view.setColorFilter(Color.parseColor(bean.getColor()), PorterDuff.Mode.LIGHTEN);
            }
            if (bean.isSelect()) {
                baseViewHolder.getView(R.id.ivFilterItemSel).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.ivFilterItemSel).setVisibility(View.INVISIBLE);
            }
        }
    }
}
